<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">

                <h:form >


                    <p:panel header="Manage Investigatio Field value suggestions and defaults" >

                        <p:panelGrid columns="1" >



                            <p:panelGrid columns="2" >


                                <h:outputLabel value="Investigation" ></h:outputLabel>
                                <p:autoComplete forceSelection="true" id="acIx"  value="#{investigationItemController.currentInvestigation}" completeMethod="#{investigationController.completeItem}" var="ix" itemLabel="#{ix.name}" itemValue="#{ix}" >
                                    <p:ajax event="itemSelect" process="acIx" update="lstIi acIiv" />
                                </p:autoComplete>
                                <h:outputLabel value="Field" ></h:outputLabel>
                                <p:selectOneMenu  id="acIiv"   value="#{investigationItemController.current}" >
                                    <f:selectItem itemLabel="Select field" />
                                    <f:selectItems value="#{investigationItemController.currentIxItems}" var="iiv" itemLabel="#{iiv.name}" itemValue="#{iiv}"  />
                                    <p:ajax event="change" process="acIiv acIx" update="lstIi" />
                                </p:selectOneMenu>
                                
                                <h:outputLabel value="Value" ></h:outputLabel>
                                <h:panelGroup >
                                    <p:inputText autocomplete="off" id="txtAdd" value="#{investigationItemController.addingString}" maxlength="250" />
                                    <p:commandButton id="btnAdd" value="Add" process="txtAdd acIx acIiv btnAdd" update="txtAdd lstIi lstIi" action="#{investigationItemController.addValueToIxItem()}" onclick="onSubmitButton();" >
                                    </p:commandButton> 

                                </h:panelGroup>


                            </p:panelGrid>

                            <p:dataTable id="lstIi" value="#{investigationItemController.current.investigationItemValues}" var="iivt" >
                                <p:column  headerText="Code">
                                    
                                    <p:inputText autocomplete="off" value="#{iivt.code}" style="width: 70px;">
                                        <p:ajax event="blur" process="lstIi" listener="#{investigationItemController.saveSelected()}" />
                                    </p:inputText>
                                </p:column>
                                <p:column headerText="Value" >
                                    <p:inputText autocomplete="off" value="#{iivt.name}" style="width: 300px;">
                                        <p:ajax event="blur" process="lstIi" listener="#{investigationItemController.saveSelected()}" />
                                    </p:inputText>
                                </p:column>
                                <p:column >
                                    <p:commandButton ajax="false" value="Remove" action="#{investigationItemController.removeInvestigationItemValue }" onclick="onSubmitButton();"  >
                                        <f:setPropertyActionListener value="#{iivt}" target="#{investigationItemController.removingItem}" />
                                    </p:commandButton>
                                </p:column>

                            </p:dataTable>

                        </p:panelGrid>


                    </p:panel>


                </h:form>
            </ui:define>

        </ui:composition>

    </h:body>
</html>
